<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>HOME</title>
</head>
<script src="./js/jquery/jquery.js"></script>
<script src="./js/common/common.js"></script>
<script src="./js/common/errorCodeHandler.js"></script>
<style>
a {
    margin-left: 20px;
}
</style>

<body>
用户：<span id="userName" style="color: red;"></span><a href="javascript:loginOut()">退出登录</a><br>
权限信息：<span id="userAuth" style="color: red;"></span><br>

登录成功，可访问页面如下：<br>
<a target="_blank" href="/study/oauth/authorize?client_id=test-pc&response_type=code&redirect_uri=https%3A%2F%2Fwww.baidu.com%2F%3Fgrant_type%3Dauthorization_code%26scope%3Dall">/oauth/authorize?client_id=test-pc&response_type=code&redirect_uri=https://www.baidu.com/?grant_type=authorization_code&scope=all</a><br>
<a target="_blank" href="/study/authenticated/test">/study/authenticated/test</a><br>

<a target="_blank" href="/static/anonymous_home.html">anonymous_home匿名用户首页</a><br>
<a target="_blank" href="/static/home.html">home首页</a><br>
<a target="_blank" href="/static/plat_user.html">plat_user对应PLAT_USER角色用户</a><br>
<a target="_blank" href="/static/plat_manage.html">plat_manage对应PLAT_MANAGE角色用户</a><br>
<a target="_blank" href="/study/h2">h2数据库</a><br>

<a target="_blank" href="/study/testCodeConfigMatcher/test1">测试权限配置是通过代码HttpSecurity在代码中配置</a><br>
<a target="_blank" href="/study/testCodeConfigMatcher/test2">测试既没有在数据库中也没有在代码中进行权限配置，最终会被anyRequest().denyAll()拦截无法访问</a><br>

</body>
<script>
    /**
     // ajax发送请求 (get / post)
     $.ajax({
        type:"GET",
        url:"/url",
        data:{id:111},
        // 返回数据前触发
        beforeSend:function (){
            console.log("数据返回前触发");
        },
        success:function (result,status,xhr){
            console.log("请求成功触发，data:"+JSON.stringify(result));
        },
        // 失败时触发
        error:function (xhr,status,error){
            console.log("请求失败触发，status:"+status);
        },
        // 无论成功失败都会触发
        complete:function (){
            console.log("请求完成触发");
        }
     });
     */
    pageInit();

    function pageInit() {
        $.ajax({
            type: "GET",
            url: "/study/authenticated/getCurrentLoginUserName",
            success: function (result, status, xhr) {
                if (!errorFilterHandler(result)) {
                    return;
                }
                $('#userName').html(result.data);
            },
            // 失败时触发
            error: function (xhr, status, error) {
                console.log("请求失败触发，status:" + status);
            }
        });

        $.ajax({
            type: "GET",
            url: "/study/authenticated/getCurrentLoginUserAuth",
            success: function (result, status, xhr) {
                if (!errorFilterHandler(result)) {
                    return;
                }
                $('#userAuth').html(JSON.stringify(result.data));
            },
            // 失败时触发
            error: function (xhr, status, error) {
                console.log("请求失败触发，status:" + status);
            }
        });
    }


    /**
     * 登出
     */
    function loginOut() {
        if (confirm("确定退出登录？")) {
            loginOutAndRedirectLogin();
        }
    }

    /**
     * 登出
     */
    function test_5_PreAuthorize() {
        $.ajax({
            type: "POST",
            url: "/study/business/test_5_PreAuthorize",
            data: JSON.stringify({username: "yyyL", password: "123456"}),
            contentType: "application/json", // 默认为application/x-www-form-urlencoded
            success: function (result, status, xhr) {
                alert(JSON.stringify(result))
            },
            // 失败时触发
            error: function (xhr, status, error) {
                console.log("请求失败触发，status:" + status);
            }
        });
    }
</script>
</html>